import Pay from '@/utils/pay.js' // 支付对象
import baseUrl from '@/utils/baseUrl.js' // api接口地址
export default {
	data() {
		return {
			sweixin: null,
			price: 888,
			type: 'accessory', //  入口标识 maintenance:维保 maintenanceorder：维保订单下单支付
			orderNo: '', //  订单号id
			payTypess: [{
					name: '微信支付',
					value: '1',
					icon: 'iconweixin',
					color: '#09BB07'
				},
				{
					name: '余额支付',
					value: '2',
					icon: 'iconyue',
					color: '#FBB000'
				}
			],
			// 支付方式列表
			payTypes: [{
					name: '支付宝支付',
					value: '0',
					icon: 'iconzhifubao',
					color: '#02A9F1'
				},
				{
					name: '微信支付',
					value: '1',
					icon: 'iconweixin',
					color: '#09BB07'
				},
				{
					name: '余额支付',
					value: '2',
					icon: 'iconyue',
					color: '#FBB000'
				}
			],
			payPlatformType: 0, // 支付平台值 0原生支付平台  20云商通支付平台
			payType: 0, //支付类型  60小程序 20支付宝

			// 支付环境
			// #ifdef H5
			payPlatformDetailType: 1,
			// #endif

			// #ifdef APP-PLUS
			payPlatformDetailType: 3,
			// #endif

			formDom: '', // 表单标签元素

			mShow6: false,
			mShowye: false,
			isSetPayPsd: false,
			paypsd: false, //支付密码
			payPassword: '', //支付密码
			couponId: '', //优惠券id
			title: '',
			isWxx: false, //是否在微信打开
			isOpen: false, //是否显示链接提示框
			isDisabledSubmitBtn: true, //按钮是否禁用
			authorizationUrl: '', //授权链接
			machineId: '', // 机器id
			info: null,
			isBindPhone: false, //是否显示绑定手机号
			phoneValue: '', //验证码值
			mobile: '',
			loginRes: {},
			aweixin: null,
			jump: '', //跳转逻辑（back为返回上一页）
		}
	},

	computed: {
		serviceNumber() {
			return this.$store.state.serviceNumber
		}
	},

	onLoad(e) {
		console.log(e)
		//#ifdef APP-PLUS
		//app判断是否有安装微信
		this.getPlus()
		//获取登录鉴权
		this.authorize()
		//#endif
		//福利购标题
		this.title = e.title
		//福利购id
		// this.couponId = e.id

		//订单号
		this.orderNo = e.orderNo
		//价格
		this.price = e.price
		//上个页面传过来的支付模块    type=maintenance||maintenanceorder维保    buyDiscountsOrder福利购  selfServiceCarWashCoupon自助洗车 selfHelpWashCar自动洗车 否则就是购车
		this.type = e.type ? e.type : '',
			//洗车机ID
			this.machineId = e.machineId ? e.machineId : ''
		// console.log(this.type)
		// 获取我的收益
		this.getUserMoneyInfo()
		this.mobile = uni.getStorageSync('Ztc_C_USER_INFO').mobile
		//#ifdef MP-WEIXIN
		//小程序使用支付的时候，后台需要的openid    将会废弃这个接口，多浪费请求-----------------------------------
		this.GetOpenid()
		//#endif
		this.jump = e.jump
	},
	onShow() {
		console.log(uni.getStorageSync('token'))
		// var vConsole = new VConsole()
		//是否设置支付密码
		this.IsExistPayPwd()

		//判断是否是微信内置浏览器
		//#ifdef H5
		let ua = window.navigator.userAgent.toLowerCase()
		if (ua.match(/MicroMessenger/i) == 'micromessenger') {
			this.isWxx = true
			this.payPlatformType = 1
			this.payPlatformDetailType = 2
			this.payType = 1
		} else {
			this.isWxx = false
		}
		//#endif
		//#ifdef MP-WEIXIN
		this.isWxx = true
		this.payPlatformType = 1
		this.payType = 1
		this.payPlatformDetailType = 4
		//#endif

		//#ifndef H5
		/* let param = plus.runtime.arguments
		console.log(param, 'asdasdasasd')
		if (param) {
		  if (Number(param) === 0) {
		    //已取消(未付)
		  } else if (Number(param) === 1) {
		    //已支付
		    this.goSuccessPage()
		  } else if (Number(param) === 2) {
		    //支付失败
		  }
		} */
		//#endif
		//回调
		//#ifdef APP-PLUS
		if (this.type === 'maintenance') {
			this.OrderMaintenancePay(res => {
				console.log(res.data.isSuccess, '支付')
				if (res.data.isSuccess) {
					// console.log('支付成功')
					this.goSuccessPage()
				} else {
					// console.log('支付失败')
				}
			})
		} else if (this.type === 'maintenanceorder') {
			this.OrderMaintenancePay(res => {
				console.log(res.data.isSuccess, '支付')
				if (res.data.isSuccess) {
					console.log('支付成功')
					this.goSuccessPage()
				} else {
					console.log('支付失败')
				}
			})
		} else if (this.type === 'buyDiscountsOrder') {
			this.checkOrderBuyDiscountsPaid(res => {
				if (res.data.isSuccess) {
					console.log('支付成功')
					this.goSuccessPage()
				} else {
					console.log('支付失败')
				}
			})
		} else if (this.type === 'butCarOrder') {

		} else if (this.type === 'selfServiceCarWashCoupon') {
			this.checkOrderCardPaid(res => {
				console.log(res.data.isSuccess, '支付')
				if (res.data.isSuccess) {
					console.log('支付成功')
					this.goSuccessPage()
				} else {
					console.log('支付失败')
				}
			})
		} else if (this.type === 'selfHelpWashCar') {
			this.queryOrderStatus(res => {
				console.log(res.data.isSuccess, '支付')
				if (res.data.isSuccess) {
					console.log('支付成功')
					this.goSuccessPage()
				} else {
					console.log('支付失败')
				}
			})
		}
		//#endif
		/* uni.getUserInfo({
		  provider: 'weixin',
		  success: function(infoRes) {
		    uni.setStorageSync('wxData', infoRes.userInfo.openId)
		  }
		}) */
	},
	/* onUnload() {
	  plus.runtime.arguments = null
	  plus.runtime.arguments = ''
	}, */
	methods: {
		//获取登录鉴权
		authorize() {
			plus.oauth.getServices(function(services) {
				console.log(services)
				for (var i in services) {
					auths[service.id] = service
				}
				aweixin = auths['weixin']
			}, function(e) {
				plus.nativeUI.alert('获取登录鉴权服务列表失败：' + JSON.stringify(e))
			})
		},
		getPlus() {
			let that = this
			var pusher = plus.share.getServices(function(s) {
				var shares = {}
				for (var i in s) {
					var t = s[i]
					shares[t.id] = t
				}
				that.sweixin = shares['weixin']
			}, function(e) {
				console.log('获取分享服务列表失败：' + e.message)
			})
		},
		// 支付方法集合
		async payApp(orderInfo) {
			console.log(orderInfo)
			switch (this.payType) {
				// 支付宝
				case 0:
					let payInfo = orderInfo.payInfo
					uni.navigateTo({
						url: '/pages_commodity/wxPay/alipay?url=' + payInfo
					})
					break
					// 微信
				case 1:
					try {
						//#ifdef MP-WEIXIN
						let infoObj = JSON.parse(orderInfo.payInfo)
						uni.requestPayment({
							'timeStamp': infoObj.timeStamp,
							'nonceStr': infoObj.nonceStr,
							'package': infoObj.package,
							'paySign': infoObj.paySign,
							'signType': infoObj.signType,
							success: res => {
								this.goSuccessPage()
								console.log('res', res)
							},
							fail: err => {
								console.log('err', err)
							}
						})
						//#endif
						//#ifndef  MP-WEIXIN
						let type
						if (baseUrl === 'https://testapi.yzsheng.com') {
							type = 2
						} else if (baseUrl === 'https://lineapi.yzsheng.com') {
							type = 0
						}
						if (this.sweixin) {
							this.sweixin.launchMiniProgram({ // 微信小程序的ID
								id: 'gh_fe19d042f1b9',
								type: type,
								path: '/pages_commodity/wxPay/wxPay?appOrderJson=' + JSON.stringify(
									orderInfo)
							})
						}
						//#endif
					} catch (err) {
						console.log('app微信支付失败', err)
						uni.showToast({
							title: '支付失败已取消支付',
							icon: 'none'
						})
					}
					break
			}
		},

		filterTel(tel) {
			let reg = /^(\d{3})\d*(\d{4})$/
			return tel.replace(reg, '$1****$2')
		},
		//获取验证码
		async onBindPhone(e) {
			try {
				let data = {
					'phone': uni.getStorageSync('Ztc_C_USER_INFO').mobile,
					'CurrentUserId': uni.getStorageSync('Ztc_C_USER_INFO').id
				}
				const res = await this.$api.fundModule.sendVerificationCode(data)
				this.isBindPhone = true
			} catch (e) {
				//TODO handle the exception
			}
		},
		//绑定手机号
		async onBindYz(e) {
			try {
				let data = {
					'phone': this.mobile,
					'verificationCode': this.phoneValue,
					'CurrentUserId': uni.getStorageSync('Ztc_C_USER_INFO').id
				}
				const res = await this.$api.fundModule.bindPhone(data)
				console.log(res)
				this.isBindPhone = false
				this.getSubmit()
			} catch (e) {
				//TODO handle the exception
			}
		},
		Onpwd(e) {
			this.phoneValue = e
		},
		//是否绑定手机号
		async getCertificationProgress() {
			try {
				let data = {
					'type': 0
				}
				const res = await this.$api.fundModule.getCertificationProgress(data)
				if (!res.data.bindPhone && this.payType !== 2) {
					this.onBindPhone()
					return
				} else {
					this.getSubmit()
				}
			} catch (e) {
				//TODO handle the exception
			}
		},
		//全自动支付是否成功
		async queryOrderStatus(call) {
			try {
				let data = {
					'id': this.orderNo
				}
				const res = await this.$api.selfServiceCarWash.queryOrderStatus(data)
				call(res)
			} catch (e) {
				//TODO handle the exception
			}
		},
		//洗车订单是否成功
		async checkOrderCardPaid(call) {
			try {
				let data = {
					'id': this.orderNo
				}
				const res = await this.$api.selfServiceCarWash.CheckOrderCardPaid(data)
				console.log('data支付的相关数据---------------------------------------')
				console.log(wx.getStorageSync('token'))
				console.log(data)
				console.log(res)
				call(res)
			} catch (e) {
				//TODO handle the exception
			}
		},
		//福利购订单是否支付成功
		async checkOrderBuyDiscountsPaid(call) {
			try {
				let data = {
					'id': this.orderNo
				}
				const res = await this.$api.maintenanceIndex.checkOrderBuyDiscountsPaid(data)
				call(res)
			} catch (e) {
				//TODO handle the exception
			}
		},
		async OrderMaintenancePay(call) {
			try {
				let data = {
					'order_id': this.orderNo
				}
				const res = await this.$api.maintenanceIndex.OrderMaintenancePay(data)
				call(res)
			} catch (e) {
				//TODO handle the exception
			}
		},
		//微信支付
		handelPay(params) {
			this.isDisabledSubmitBtn = true //防止用户点击多次
			this.weixinPay(params)
		},
		//解决微信内置对象报错
		weixinPay(params) {
			var that = this
			if (typeof WeixinJSBridge === 'undefined') {
				if (document.addEventListener) {
					document.addEventListener('WeixinJSBridgeReady', that.onBridgeReady(params), false)
				} else if (document.attachEvent) {
					document.attachEvent('WeixinJSBridgeReady', that.onBridgeReady(params))
					document.attachEvent('onWeixinJSBridgeReady', that.onBridgeReady(params))
				}
			} else {
				that.onBridgeReady(params)
			}
		},
		//微信内置浏览器类
		onBridgeReady(datas) {
			let data = JSON.parse(datas)
			console.log(data)
			var that = this
			// var timestamp = Math.round(that.weChatParameter.timeStamp).toString();
			WeixinJSBridge.invoke(
				'getBrandWCPayRequest', {
					'appId': data.appId, //公众号ID，由商户传入
					'timeStamp': data.timeStamp, //时间戳，自1970年以来的秒数
					'nonceStr': data.nonceStr, //随机串
					'package': data.package,
					'signType': data.signType, //微信签名方式：
					'paySign': data.paySign
				},
				function(res) {
					// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
					if (res.err_msg == 'get_brand_wcpay_request:ok') { //支付成功后的操作
						console.log('支付成功')
						that.isDisabledSubmitBtn = true
						//福利购样微信支付
						if (that.type === 'buyDiscountsOrder') {
							that.getCouponIdByBuyDiscountsOrderId()
						} else if (that.type === 'maintenance') { //维保支付
							that.goSuccessPage()
						} else if (that.type === 'maintenanceorder') { //保养订单支付
							that.goSuccessPage()
						} else if (that.type === 'butCarOrder') { //购车保证金支付
							that.goSuccessPage()
						} else if (that.type === 'selfServiceCarWashCoupon') { //自助洗车购买优惠券支付
							that.selfServiceCarWashCouponSuccess()
						}
					} else if (res.err_msg == 'get_brand_wcpay_request:cancel') { //取消支付的操作
						console.log('取消支付')
						that.isDisabledSubmitBtn = false //按钮恢复高亮
					} else { //支付失败的操作
						console.log('支付失败')
						that.isDisabledSubmitBtn = false //按钮恢复高亮
					}
				}
			)
		},
		//是否设置支付密码
		async IsExistPayPwd() {
			try {
				const res = await this.$api.user.IsExistPayPwd()
				this.isSetPayPsd = res.data
			} catch (e) {
				console.log(e)
			}
		},

		// 单选监听
		radioChange(e) {
			this.payType = Number(e.target.value)
			// console.log(e.target.value, '123')
		},

		//获取优惠券id(福利购，支付成功之后调用)
		async getCouponIdByBuyDiscountsOrderId() {
			try {
				let data = {
					'buyDiscountsId': this.orderNo
				}
				const res = await this.$api.maintenanceIndex.getCouponIdByBuyDiscountsOrderId(data)
				this.couponId = res.data
				console.log(res)
				//#ifdef APP-PLUS
				uni.redirectTo({
					url: '/pages_commodity/myLoveCar/myLoveCar?type=100' + '&id=' + this.couponId +
						'&title=' + this.title
				})
				//#endif
				//#ifdef H5
				if (this.isWxx) {
					window.location.href = encodeURI(window.location.origin + window.location.pathname +
						`#/pages_commodity/myLoveCar/myLoveCar?title=${this.title}&type=100&orderId=${this.orderNo}&id=${this.couponId}&t=${new Date().getTime()}`
					)
				}
				//#endif
			} catch (e) {
				//TODO handle the exception
			}
		},
		// 自助洗车优惠券购买成功
		selfServiceCarWashCouponSuccess() {
			this.$store.commit('setMachineId', '')
			//#ifdef APP-PLUS || MP-WEIXIN
			if (this.machineId) {
				uni.redirectTo({
					url: `/pages_commodity/selfWash/existingOrder?id=${this.machineId}`
				})
			} else {
				uni.showToast({
					title: '支付成功',
					icon: 'success'
				})
				setTimeout(() => {
					uni.redirectTo({
						url: '/pages_commodity/selfWash/selfWash'
					})
				}, 1000)
			}
			//#endif

			//#ifdef H5

			if (this.machineId) {
				window.location.replace(encodeURI(window.location.origin + window.location.pathname +
					`#/pages_commodity/selfWash/existingOrder?id=${this.machineId}`))
			} else {
				console.log(this.jump)
				setTimeout(() => {
					if (this.jump === 'back') {
						uni.navigateBack({
							delta: 1
						})
					} else {
						uni.redirectTo({
							url: '/pages_commodity/selfWash/selfWash'
						})
					}

				}, 1000)
			}

			//#endif
		},
		// 跳转到成功页面
		goSuccessPage() {
			if (this.type === 'buyDiscountsOrder') {
				this.getCouponIdByBuyDiscountsOrderId()
			} else if (this.type === 'selfServiceCarWashCoupon' || this.type === 'selfHelpWashCar') {
				this.selfServiceCarWashCouponSuccess()
			} else {
				this.goSuccess()
			}

		},
		//支付成功跳转(通用)
		goSuccess() {
			//#ifdef APP-PLUS || MP-WEIXIN
			uni.redirectTo({
				url: '/pages_commodity/paySuccessful/paySuccessful'
			})
			//#endif

			//#ifdef H5
			window.location.href = encodeURI(window.location.origin + window.location.pathname +
				'#/pages_commodity/paySuccessful/paySuccessful')
			//#endif
		},
		//小程序使用支付的时候，后台需要的openid    将会废弃这个接口，多浪费请求-----------------------------------
		async GetOpenid() {
			try {
				//#ifdef MP-WEIXIN
				let data = {
					'access_token': '',
					'openid': uni.getStorageSync('wxData').openid,
					'unionid': ''
				}
				console.log(uni.getStorageSync('wxData'))
				const ress = await this.$api.commodity.YstWxPayGetWxInfo(data)
				// console.log(res, data)
				//#endif
			} catch (e) {
				//TODO handle the exception
			}
		},
		//app使用小程序支付的时候需要用的到openid    将会废弃这个接口，多浪费请求-----------------------------------
		async YstWxPayGetWxInfo(loginRes) {
			try {
				//#ifdef APP-PLUS
				let data = {
					'access_token': loginRes.authResult.access_token,
					'openid': loginRes.authResult.openid,
					'unionid': loginRes.authResult.unionid
				}
				const res = await this.$api.commodity.YstWxPayGetWxInfo(data)
				// console.log(res, data)
				//#endif
			} catch (e) {
				uni.hideLoading()
			}
		},

		// H5端支付方法
		payH5(data) {
			switch (this.payPlatformType) {
				// 支付宝
				case 0:
					this.formDom = data
					this.$nextTick(() => {
						document.forms['submit'].submit()
					})
					break

					// 微信
				case 1:
					let a = document.createElement('a')
					a.href = data.mwebUrl
					a.target = '_blank'
					a.click()
					// window.location.href = data.mwebUrl
					break
			}
		},

		//余额支付
		async ClientBalancePay() {
			let payModule = null
			if (this.type === 'maintenance' || this.type === 'maintenanceorder') {
				payModule = 3
			} else if (this.type === 'buyDiscountsOrder') {
				payModule = 4
			} else if (this.type === 'selfServiceCarWashCoupon') {
				payModule = 7
			} else if (this.type === 'selfHelpWashCar') {
				payModule = 8
			} else {
				payModule = 2
			}
			if (this.payPassword.length === 6) {
				let data = {
					id: this.orderNo,
					userInputPayPassword: this.payPassword,
					payModule: payModule //购车--2 维保--3 福利购--4
				}
				try {
					const res = await this.$api.common.ClientBalancePay(data)
					console.log('余额支付', res)
					if (res.code == '-4') {
						uni.showToast({
							title: res.parmeter || res.msg,
							icon: 'none'
						})
					} else if (res.code === 200) {
						uni.showToast({
							title: '支付成功！',
							icon: 'success'
						})
						if (this.type === 'maintenance') {
							this.goSuccessPage()
						} else if (this.type === 'maintenanceorder') {
							this.goSuccessPage()
						} else if (this.type === 'buyDiscountsOrder') {
							//福利购余额支付
							//#ifdef APP-PLUS
							this.getCouponIdByBuyDiscountsOrderId()
							//#endif
							//#ifdef H5
							window.location.href = window.location.origin + window.location.pathname +
								`#/pages_commodity/myLoveCar/myLoveCar?title=${this.title}&type=100&orderId=${this.orderNo}`
							//#endif
						} else if (this.type === 'butCarOrder') {
							this.goSuccessPage()
						} else if (this.type === 'selfServiceCarWashCoupon') {
							this.selfServiceCarWashCouponSuccess()
						}
					} else {
						uni.showToast({
							title: res.parmeter || res.msg,
							icon: 'none'
						})
					}
					this.paypsd = false

				} catch (err) {

				}
			} else {
				uni.showToast({
					title: '请输入正确的支付密码',
					icon: 'none'
				})
			}
		},
		//购车保证金支付方法
		async carGoodsPay() {

			let data = {
				orderId: this.orderNo,
				payModule: 2,
				payPlatform: {
					payPlatformType: this.payPlatformType, // 支付平台
					payPlatformDetailType: Number(this
						.payPlatformDetailType) // 支付环境，H5端还是APP端等0：PC扫描，1：H5，2：微信H5，3：APP支付，4：小程序
				},
				// #ifdef MP-WEIXIN
				// openid: uni.getStorageSync('wxData').openid,
				// #endif
				// #ifdef H5
				returnUrl: encodeURI(
					window.location.origin + window.location.pathname +
					`#/pages_commodity/paySuccessful/paySuccessful?id=${this.orderNo}&type=${this.type}`
				)
				// #endif
			}
			console.log(data)
			try {
				const res = await this.$api.commodity.OrderBuyCarEarnestMoneyPay(data)
				console.log('车品支付接口成功', res)
				// #ifdef APP-PLUS || MP-WEIXIN
				this.payApp(res.data.data)

				// #endif

				// #ifdef H5
				if (this.isWxx) {
					this.handelPay(res.data.data.parameter)
				} else {
					this.payH5(res.data.data)
				}
				// #endif
			} catch (err) {
				uni.showToast({
					title: '车品支付接口错误'
				})
				console.log('车品支付接口错误', err)
			}
		},
		// 维保调用支付方法
		async maintenancePay() {
			let data = {
				id: this.orderNo,
				payModule: 3,
				payPlatform: {
					payPlatformType: this.payPlatformType, // 支付平台
					payPlatformDetailType: Number(this
						.payPlatformDetailType) // 支付环境，H5端还是APP端等0：PC扫描，1：H5，2：微信H5，3：APP支付，4：小程序
				},
				// #ifdef MP-WEIXIN
				// openid: uni.getStorageSync('wxData').openid,
				// #endif
				// #ifdef H5
				returnUrl: encodeURI(window.location.origin + window.location.pathname +
					`#/pages_commodity/paySuccess/paySuccess?id=${this.orderNo}&type=${this.type}`)
				// #endif
			}
			console.log(data)
			try {
				const res = await this.$api.maintenanceOrder.OrderMaintenancePay(data)
				console.log('维保支付接口成功', res)
				// #ifdef APP-PLUS || MP-WEIXIN
				this.payApp(res.data.data)

				// #endif

				// #ifdef H5
				if (this.isWxx) {
					this.handelPay(res.data.data.parameter)
				} else {
					this.payH5(res.data.data)
				}
				// #endif
			} catch (err) {
				uni.showToast({
					title: '维保支付接口错误',
					icon: 'none'
				})
				console.log('车品支付接口错误', err)
			}
		},

		// 保养订单支付
		async maintenanceOrderPay() {
			let data = {
				id: this.orderNo,
				payModule: 3,
				payPlatform: {
					payPlatformType: this.payPlatformType, // 支付平台
					payPlatformDetailType: Number(this
						.payPlatformDetailType) // 支付环境，H5端还是APP端等0：PC扫描，1：H5，2：微信H5，3：APP支付，4：小程序
				},
				// #ifdef MP-WEIXIN
				// openid: uni.getStorageSync('wxData').openid,
				// #endif
				// #ifdef H5
				returnUrl: encodeURI(window.location.origin + window.location.pathname +
					`#/pages_commodity/paySuccess/paySuccess?id=${this.orderNo}&type=${this.type}`)
				// #endif
			}
			console.log(data, '参数')
			try {
				const res = await this.$api.maintenanceOrder.OrderMaintenancePay(data)
				console.log('维保支付接口成功', res)
				// #ifdef APP-PLUS || MP-WEIXIN
				this.payApp(res.data.data)

				// #endif

				// #ifdef H5
				if (this.isWxx) {
					this.handelPay(res.data.data.parameter)
				} else {
					this.payH5(res.data.data)
				}
				// #endif
			} catch (err) {
				uni.showToast({
					title: '维保支付接口错误',
					icon: 'none'
				})
				console.log('维保支付接口错误', err)
			}
		},

		// 福利购订单支付
		async buyDiscountsOrder() {
			let data = {
				orderId: this.orderNo,
				payModule: 4,
				payPlatform: {
					payPlatformType: this.payPlatformType, // 支付平台
					payPlatformDetailType: Number(this
						.payPlatformDetailType) // 支付环境，H5端还是APP端等0：PC扫描，1：H5，2：微信H5，3：APP支付，4：小程序
				},
				// #ifdef MP-WEIXIN
				// openid: uni.getStorageSync('wxData').openid,
				// #endif
				// #ifdef H5
				returnUrl: encodeURI(window.location.origin + window.location.pathname +
					`#/pages_commodity/myLoveCar/myLoveCar?title=${this.title}&type=100&orderId=${this.orderNo}`
				)
				// #endif
			}
			console.log(data, '123')
			try {
				const res = await this.$api.maintenanceIndex.payBuyDiscountsOrder(data)
				console.log('福利购支付成功', res)
				// #ifdef APP-PLUS || MP-WEIXIN
				this.payApp(res.data.data)
				// #endif
				// #ifdef H5
				//判断微信内置浏览器支付方法
				if (this.isWxx) {
					this.handelPay(res.data.data.parameter)
				} else {
					this.payH5(res.data.data)
				}
				// #endif
			} catch (err) {
				console.log('福利购支付接口错误', err)
			}
		},

		// 自助洗车优惠券支付
		async selfServiceCarWashCoupon() {
			let _this = this

			let data = {
				orderId: this.orderNo,
				payModule: 7,
				// payPlatform: {
				//   payPlatformType: this.payPlatformType, // 支付平台
				//   payPlatformDetailType: Number(this.payPlatformDetailType) // 支付环境，H5端还是APP端等0：PC扫描，1：H5，2：微信H5，3：APP支付，4：小程序
				// },
				// #ifdef H5
				returnUrl: encodeURI(window.location.origin + window.location.pathname +
					`#/pages_commodity/paySuccess/paySuccess?id=${this.orderNo}&type=${this.type}`)
				// #endif
			}

			console.log(data, '123')
			try {
				//#ifdef MP-WEIXIN
				wx.login({
					success(code) {
						data.PayType = 1
						data.Code = encodeURIComponent(code.code)
						_this.$api.selfServiceCarWash.selfServiceCarWash(data).then(res => {
							console.log(res)
							_this.payApp(res.data)
						})
					}
				})
				//#endif

				// #ifdef H5
				const res = await this.$api.selfServiceCarWash.selfServiceCarWash(data)
				uni.hideLoading()
				if (this.isWxx) {
					this.handelPay(res.data.data.parameter)
				} else {
					this.payH5(res.data.data)
				}
				// #endif

				// #ifdef APP-PLUS
				//app获取后台组装好的id
				uni.hideLoading()
				if (this.payType === 1) {
					this.payApp({
						orderId: data.orderId,
						payModule: data.payModule,
						token: uni.getStorageSync('token')
					})
				} else {
					data.PayType = 2
					console.log(data)
					await this.$api.selfServiceCarWash.selfServiceCarWash(data).then(res => {
						this.payApp(res.data)
					})
				}
				// #endif

			} catch (err) {
				uni.hideLoading()
				uni.showToast({
					title: err,
					icon: 'none'
				})
				console.log('自助洗车会员支付接口错误', err)
			}
		},
		//支付数据组装区
		async selfHelpWashCar() {
			let data = {
				orderId: this.orderNo,
				payModule: 8,
				payPlatform: {
					payPlatformType: this.payPlatformType, // 支付平台
					payPlatformDetailType: Number(this
						.payPlatformDetailType) // 支付环境，H5端还是APP端等0：PC扫描，1：H5，2：微信H5，3：APP支付，4：小程序
				},
				// #ifdef H5
				returnUrl: encodeURI(window.location.origin + window.location.pathname +
					`#/pages_commodity/paySuccess/paySuccess?id=${this.orderNo}&type=${this.type}`)
				// #endif
			}
			try {
				console.log(data)
				const res = await this.$api.selfServiceCarWash.payOrder(data)
				uni.hideLoading()
				//#ifdef APP-PLUS
				this.payApp(res.data.data)
				//#endif
				// #ifdef MP-WEIXIN
				this.payApp(res.data.data)
				// #endif

				// #ifdef H5
				if (this.isWxx) {
					this.handelPay(res.data.data.parameter)
				} else {
					this.payH5(res.data.data)
				}
				// #endif
			} catch (err) {
				uni.hideLoading()
				uni.showToast({
					title: err,
					icon: 'none'
				})
				console.log('自助洗车会员支付接口错误', err)
			}
		},
		//支付处理
		getPayType() {
			if (this.type === 'maintenance') {
				this.maintenancePay()
			} else if (this.type === 'maintenanceorder') {
				this.maintenanceOrderPay()
			} else if (this.type === 'buyDiscountsOrder') {
				this.buyDiscountsOrder()
			} else if (this.type === 'butCarOrder') {
				this.carGoodsPay()
			} else if (this.type === 'selfServiceCarWashCoupon') {
				this.selfServiceCarWashCoupon()
			} else if (this.type === 'selfHelpWashCar') {
				this.selfHelpWashCar()
			}
		},
		//余额支付input值
		finish(e) {
			console.log(e)
			this.payPassword = e
		},
		getSubmit() {
			if (this.payType === 2) {
				if (this.isSetPayPsd) {
					this.paypsd = true
				} else {
					uni.showToast({
						title: '请先设置支付密码',
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages_userModule/setPassword/setPsd'
						})
					}, 1200)
				}
			} else {
				let _this = this
				let payType = this.payType
				let platform = ''
				// #ifdef APP-PLUS
				if (payType === 0) {
					platform = 20 // 支付宝app支付(50)
					this.payPlatformType = 20
					this.payPlatformDetailType = platform
					this.getPayType()
				} else if (payType === 1) {
					uni.showLoading()
					let openid = uni.getStorageSync('wxData')
					platform = 60 // 微信app支付（55）
					this.payPlatformType = 20
					this.payPlatformDetailType = platform
					this.getPayType()

				}
				// #endif
				// #ifdef H5
				if (this.isWxx) {
					platform = 2
				} else {
					platform = 1
				}
				this.payPlatformType = 0
				this.payPlatformDetailType = platform
				// #endif
				// #ifdef MP-WEIXIN
				if (payType === 1) {
					platform = 60 // 微信小程序支付
				} else if (payType === 2) {
					platform = 50 // 余额
				}
				this.payPlatformType = 20
				this.payPlatformDetailType = platform
				// #endif

				// #ifndef APP-PLUS
				this.getPayType()
				//#endif
			}
		},
		// 点击确认支付
		submit() {
			this.getSubmit()
		},

		// 打电话
		call() {
			AddMobileContactData(this.$store.state.userInfoDetail.store.storeId)
			uni.makePhoneCall({
				phoneNumber: this.serviceNumber.number
			})
		},

		confirmHE() {},
		confirm() {},

		async getUserMoneyInfo() {
			try {
				const res = await this.$api.me.getUserMoneyInfo({})
				// console.log(res)
				this.info = res.data
			} catch (e) {
				console.log(e)
				plus.runtime.arguments = null
				plus.runtime.arguments = ''
			}
		}
	}
}
